#ifndef _ZM_SPEC_H_
#define _ZM_SPEC_H_

/*
 * spec format:
 * -------------------------------------------------------------------
 * HEADERS(2B)| LENGTH(2B) |CMD(1B) | DATAS(X) | CHECKSUM(1B) | END(1B)
 * -------------------------------------------------------------------
 * 0x40 0x21  | low high   |0x xx   | 0x xx ...|SUM([0],[DATAS]| 0x23
 * -------------------------------------------------------------------
 *
 */
#define SPEC_ZM 0x8001

#define ZM_SPEC_LOG "zmipc.log"
#define ZM_SPEC_CAT "qqzm"

#define ZM_LOCAL_PORT 2233
#define ZM_BROADCAST_PORT 3322

#define CMD_HEADER_F 0x40
#define CMD_HEADER_S 0x21
#define CMD_TAIL 0x23

#define PACKET_CMD_POS 4
#define PACKET_DATA_POS 5

/*
 * cmd spec
 */
// down to device
#define REQ_CMD_MIN 0x59 // invalid cmd min limit
#define GET_DEV_STATUS 0x60
#define SET_DEV_IPCFGS 0x61
#define GET_DEV_DNSINF 0x62
#define GET_P2P_STATUS 0x63
#define SET_OTH_NETCFG 0x64
#define REQ_CMD_MAX 0x65 // invalid cmd max limit

// up to tool
#define RES_CMD_MIN 0x70
#define RES_DEV_STATUS 0x71
#define RES_DEV_IPCFGS 0x72
#define RES_DEV_DNSINF 0x73
#define RES_P2P_STATUS 0x74
#define RES_OTH_NETCFG 0x75
#define RES_CMD_MAX 0x76

/*
 * datas spec
 */
typedef enum
{
	DHCP_ON = 1,
   	DHCP_OFF
}DHCP_SWITCH;

/*
 * DES Encryption
 */
#define DEMO_DNS "www.zmvideo.com.cn"
#define DES_SUBKEY "zmIpCamzmIpCamzm"

/*
 * App Exception Handle
 */
#define ZM_TIMEOUT 10 //unit:s
#define ZM_TRYCNT 3 //try again times

#define DEV_ID_LEN 9

#define IPv4_LEN 16
typedef struct IP_Array_S
{
	char dev_ip[IPv4_LEN];
	char subnet[IPv4_LEN];
	char defgw[IPv4_LEN];
	char dnsip[IPv4_LEN];
}IP_Array;

typedef struct Port_NetCfg_S
{
	DHCP_SWITCH dhcp_flag;
	unsigned short web_port;
	unsigned short video_port;
}Port_NetCfg;

typedef struct Device_Status_Info_S
{
	char dev_id[DEV_ID_LEN+7];
	IP_Array ipaddrs;
	Port_NetCfg port_info;
	char macaddr[64];
	char version[16];
}Device_Stat_Info;

typedef struct Device_DNS_Info_S
{
	unsigned char dev_id[DEV_ID_LEN+7];
	char dnsname[32];
	char code[16];
}Device_DNS_Info;

/*
 * export api
 */
int zm_build_get_status(char *buff,int *len);
int zm_build_setip(const char *devid,IP_Array *ipaddrs, char *buff, int *len);
int zm_build_get_dns(char *buff,int *len);
int zm_build_getp2p(char *buff,int *len);
int zm_build_set_netcfg(const char *devid, Port_NetCfg *port_net,char *buff,int *len);
int zm_parse_packet(const char *buff, void *data, int *data_len,unsigned char reqcmd);

#endif

